﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INTROSE
{
    public partial class Add_User : Form
    {
        SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Database = Introse; Integrated Security = True");
        private string name, position;
        public Add_User(string name, string position)
        {
            InitializeComponent();
            this.name = name;
            this.position = position;
        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
            MenuExecutive menu = new MenuExecutive(name, position);
            menu.Show();
        }

        private void btnAdd_Click_1(object sender, EventArgs e)
        {
            {
                if ((!txtConfirmPw.Text.Equals(txtNewPw.Text)) || (txtAdd.Text == "" || txtConfirmPw.Text == "" || txtEAdd.Text == "" || txtName.Text == "" || txtNewPw.Text == "" || txtConfirmPw.Text == "" || txtUsername.Text == "" || comboPos.Text == "" || comboPos.Text == "       Select Position"))
                {
                    if (!txtConfirmPw.Text.Equals(txtNewPw.Text))
                        MessageBox.Show("The entered passwords doesn't match with each other! Please enter correctly!");
                    else
                        MessageBox.Show("Please fill up the empty fields, unchecked boxes and/or unclicked buttons");
                }
                else 
                {
                    con.Open();
                    SqlCommand command1 = new SqlCommand("Insert into users Values('" + txtUsername.Text + "','" + txtConfirmPw.Text + "','" + comboPos.Text + "','" + txtName.Text + "','" + txtAdd.Text + "','" + txtEAdd.Text + "')", con);
                    command1.ExecuteNonQuery();
                    MessageBox.Show("Successfully added a user!");
                    con.Close();
                    this.Close();
                    MenuExecutive menu = new MenuExecutive(name, position);
                    menu.Show();
                }
            }
        }
    }
}
